package com.megafaves.site;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class MegafavesSiteServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {

		resp.setContentType("text/plain");
		resp.getWriter().println("Hello, world");

		String host = req.getHeader("host");

		if (host.startsWith("ebay")) {

			resp.getWriter().println("ebay");

			// RequestDispatcher dispatcher = req
			// .getRequestDispatcher("http://www.ebay.com/sch/megafaves/m.html");
			// try {
			// //dispatcher.forward(req, resp);
			// } catch (ServletException e) {
			// e.printStackTrace();
			// }
			resp.sendRedirect("http://www.ebay.com/sch/megafaves/m.html");
			
			return;
		}

		if (host.startsWith("store")) {

			resp.getWriter().println("store");

			resp.sendRedirect("http://stores.ebay.com/Megafaves-Imports");
			
			
		}

		// resp.getWriter().println();
	}
}
